﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using Kenly.DBFramework.Gateway;

namespace Kenly.DBFramework.Tests
{


    static class EntityMapperHelper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static Student CreateEmptyEntity()
        {
            return new Student();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IList CreateEmptyEntities()
        {
            IList entities = new List<Student>();
            entities.Add(new Student());
            entities.Add(new Student());

            return entities;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<Student> CreateGenericEmptyEntities()
        {
            List<Student> entities = new List<Student>();
            entities.Add(new Student());
            entities.Add(new Student());

            return entities;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //public static Student CreateEntity()
        //{
        //    return new Student { StudentID = 100, NationalIDNumber = "1234" };
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<Student> CreateGenericEntities()
        {
            List<Student> employees = new List<Student>();
            employees.Add(new Student { StudentID = 100, NationalIDNumber = "1234" });
            employees.Add(new Student { StudentID = 101, NationalIDNumber = "5678" });
            return employees;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IList CreateEntities()
        {
            List<Student> employees = new List<Student>();
            employees.Add(new Student { StudentID = 100, NationalIDNumber = "1234" });
            employees.Add(new Student { StudentID = 101, NationalIDNumber = "5678" });
            return employees;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static Type GetEntityType()
        {
            return typeof(Student);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable CreateAdaptedTable()
        {
            DataTable dataTable = new DataTable();
            dataTable.TableName = "Student";

            dataTable.Columns.Add("StudentID");
            dataTable.Columns.Add("NationalIDNumber");
            dataTable.Columns.Add("Birthday");
            dataTable.Columns["StudentID"].DataType = typeof(int);
            dataTable.Columns["NationalIDNumber"].DataType = typeof(string);
            dataTable.Columns["Birthday"].DataType = typeof(DateTime);

            DataRow row = dataTable.NewRow();
            row["StudentID"] = 100;
            row["NationalIDNumber"] = "1234";
            row["Birthday"] = DateTime.Parse("1990-10-1");
            dataTable.Rows.Add(row);

            row = dataTable.NewRow();
            row["StudentID"] = 101;
            row["NationalIDNumber"] = "5678";
            dataTable.Rows.Add(row);

            return dataTable;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataTable CreateRawTable()
        {
            DataTable dataTable = new DataTable();
            dataTable.TableName = "base_Student";

            dataTable.Columns.Add(Student.StudentIDColumn);
            dataTable.Columns.Add(Student.NationalIDNumberColumn);
            dataTable.Columns.Add(Student.BirthdayColumn);
            dataTable.Columns[Student.StudentIDColumn].DataType = typeof(int);
            dataTable.Columns[Student.NationalIDNumberColumn].DataType = typeof(string);
            dataTable.Columns[Student.BirthdayColumn].DataType = typeof(DateTime);

            DataRow row = dataTable.NewRow();
            row[Student.StudentIDColumn] = 100;
            row[Student.NationalIDNumberColumn] = "1234";
            row[Student.BirthdayColumn] = DateTime.Parse("1990-10-1");
            dataTable.Rows.Add(row);

            row = dataTable.NewRow();
            row[Student.StudentIDColumn] = 101;
            row[Student.NationalIDNumberColumn] = "5678";
            dataTable.Rows.Add(row);

            return dataTable;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DataRow CreateAdaptedDataRow()
        {
            DataTable dataTable = CreateAdaptedTable();

            return dataTable.Rows[0];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static List<ColumnAttribute> CreateColumnAttributes()
        {
            List<ColumnAttribute> columnAttributes = new List<ColumnAttribute>();
            columnAttributes.Add(new ColumnAttribute { ColumnName = Student.StudentIDColumn, PropertyName = "StudentID" });
            columnAttributes.Add(new ColumnAttribute { ColumnName = Student.NationalIDNumberColumn, PropertyName = "NationalIDNumber" });
            columnAttributes.Add(new ColumnAttribute { ColumnName = Student.BirthdayColumn, PropertyName = "Birthday" });

            return columnAttributes;

        }
    }
}
